;
$('.form-item-phone,.phonecode-left,.btn-phonecode').mouseover(function () {
    $(this).addClass('hover');
}).mouseleave(function () {
    $(this).removeClass('hover');
});

$('.form-item input').focus(function () {
    $(this).parents('.form-item').next('.input-tip').find('.error').addClass('hide');
});
$("#step1-next").click(function () {
    if(!verifyPhone()||!checkPhoneCode()){
        return false;
    }
    $('#step2-wrap').show();
    $('#step1-wrap').hide();
    $('.pro-step[for="step1-wrap"]').removeClass('cur-step').addClass('done-step').find('.step-index').text('');
    $('.pro-step[for="step2-wrap"]').addClass('cur-step').prev('.pro-line').addClass('person-cur-line');
});
$("#back-btn").click(function () {
    $('#step2-wrap').hide();
    $('#step1-wrap').show();
    $('.pro-step[for="step2-wrap"]').removeClass('cur-step');
    $('.pro-step[for="step1-wrap"]').addClass('cur-step').removeClass('done-step').next('.pro-line').removeClass('person-cur-line');
    $('.pro-step[for="step1-wrap"]').find('.step-index').text('1');
});

function verifyPhone() {
   var phone =  $('#form-phone').val();
   if(phone == '' || phone == undefined){
       $("#form-phone-error").removeClass('hide');
       return false;
   }
    var regu = /^[1][3-9][0-9]{9}$/;
    var re = new RegExp(regu);
    if (!re.test(phone)) {
        $("#form-phone-error").removeClass('hide').find('.msg').text('请输入正确的手机号');
        return false;
    }
   return  true;
}

function checkPhoneCode() {
    return  true;
    var phone =  $('#phoneCode').val();
    if(phone == '' || phone == undefined){
        $("#form-phonecode-error").removeClass('hide').find('.msg').text('请输入验证码');
        return false;
    }

}

$('#form-register').click(function () {
    var url = $('#register-form').attr('action');
    var data  = $('#register-form').serialize();
    $(this).prop("disabled", true).text('正在注册...');
    $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data: data
    }).done(function (response) {
        if(response.status){
            location.href = response.url;
        }else{
            showErrorTips("#other-error-tip .error",response.msg);
        }
    }).fail(function (XMLHttpRequest) {
        var errorText = '';
        if (XMLHttpRequest.status == 422) {
            var errors = XMLHttpRequest.responseJSON.errors;
            if(typeof errors == 'object') {
                for (var index in errors) { // 不推荐这样
                    errorText = errors[index][0];
                }
            }else{
                errorText = XMLHttpRequest.responseJSON.msg;
            }
        }else{
            errorText = '网络获取服务器数据出现问题'
        }
        showErrorTips("#other-error-tip .error",errorText);

    }).always(function () {
        setTimeout(function () {
            $('#form-register').removeAttr("disabled").text('立即注册');
        },2000);
    });
});

function showErrorTips(obj,errorText) {

    $(obj).removeClass('hide').find('.msg').text(errorText);
    return false;
}